package com.example.alert;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

import com.lnlyj.alert.ActionView;
import com.lnlyj.alert.Alert;
import com.lnlyj.alert.LObject;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {
    Alert alert;
    List<LObject> list;

    class Data implements LObject {

        String string;

        public Data(String string) {
            this.string = string;
        }

        @Override
        public String getText() {
            return string;
        }
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        View contentView  = View.inflate(this, R.layout.activity_main, null);
        setContentView(contentView);

        list = new ArrayList<>();

        for (int i = 0; i < 9; i++) {
            list.add(new Data((i+1)+""));
        }

        contentView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                new Alert.Builder(MainActivity.this)
                        .withStyle(Alert.Style.ALERT)
                        .withTitle("喜欢哪一个？")
                        .withArray(list, false, new Alert.OnItemSelectedListener() {
                            @Override
                            public void onSingleItemClick(LObject obj) {
                                Log.d("MainActivity", "onSingleItemClick: ");
                            }

                            @Override
                            public void onMultiItemSelected(List<LObject> selected) {
                                Log.d("MainActivity", "onMultiItemSelected: ");
                            }
                        })
                        .withAction("Action1", new ActionView.ActionCallback() {
                            @Override
                            public void onAction(View v) {
                                Toast.makeText(MainActivity.this, "Action1", Toast.LENGTH_SHORT).show();
                            }
                        })
                        .withAction("Action2", new ActionView.ActionCallback() {
                            @Override
                            public void onAction(View v) {
                                Toast.makeText(MainActivity.this, "Action2", Toast.LENGTH_SHORT).show();
                            }
                        })
                        .withCancelable(true)
                        .show();

            }
        });

    }
}
